<template>
	<view class="container">
		<view class="header">
			<view class="user">
				<view class="left">
					<view class="avatar">
						<u--image :src="author.avatar.file_path" width="120rpx" height="120rpx" shape="circle">
						</u--image>
					</view>
					<view class="nickName">
						<view class="top">
							<view class="name">{{ author.real_name }}</view>
							<view class="icon">
								<u-icon
									name="https://img.alicdn.com/imgextra/i1/2064565174/O1CN01xeJcrO1o5k37Qfk1I_!!2064565174.gif">
								</u-icon>
							</view>
						</view>
						<view class="bottom" v-if="author.user_id" @click="onCopyPassword">
							口令：{{ author_id }}* (点击复制)
						</view>
					</view>
				</view>
				<view class="right">
					<u-subsection bgColor="#ffffff" :list="subsection" :current="0"></u-subsection>
				</view>
			</view>
			<view class="remarks">
				{{ author.remarks }}
			</view>
			<!-- 按钮 -->
			<view class="btn-group">
				<view class="left" @click="is_wechat = true">
					<view class="btn">
						<u-button iconColor="#fff" icon="kefu-ermai" color="#2b85e4" shape="circle" text="专属AI定制">
						</u-button>
					</view>
				</view>
				<view class="right">
					<view class="btn">
						<u-button open-type="share" icon="share" text="分享" shape="circle"></u-button>
					</view>
					<view class="btn" @click="is_statement = true">
						<u-button icon="question-circle" text="声明" shape="circle"></u-button>
					</view>
				</view>
			</view>
		</view>
		<view class="tabs">
			<u-tabs :list="tabs" @click="click"></u-tabs>
		</view>
		<!-- 推荐红包列表 -->
		<view class="cover" v-if="opus.length > 0">
			<view class="image" @click="onSubmitOrder(item.opus_id)" v-for="(item,index) in opus" :key="index">
				<u--image height="180" mode="scaleToFill" width="100%" radius="5" :src="item.image.file_path">
				</u--image>
			</view>
		</view>
		<view v-else>
			<u-empty mode="data" text="作者很懒,啥也没有~!" icon="http://cdn.uviewui.com/uview/empty/data.png">
			</u-empty>
		</view>
		<!-- 首次公告 -->
		<u-modal @confirm="onCloseAll" @cancel="onCloseAll" @close="onCloseAll" :closeOnClickOverlay="true"
			:show="is_copyright" confirmText="我已知晓" :showCancelButton="true" title="版权声明" :content='copyright'>
		</u-modal>
		<!-- 创作者声明 -->
		<u-modal @confirm="onCloseAll" @cancel="onCloseAll" @close="onCloseAll" :closeOnClickOverlay="true"
			:show="is_statement" confirmText="我已知晓" :showCancelButton="true" title="创作者声明" :content='author.statement'>
		</u-modal>
		<!-- 联系创作者 -->
		<u-modal @confirm="onCloseAll" @cancel="onCloseAll" @close="onCloseAll" :closeOnClickOverlay="true"
			:show="is_wechat" confirmText="我已知晓" :showCancelButton="true" title="联系创作者" :content='author.mobile'>
		</u-modal>
	</view>
</template>

<script>
	import {
		category
	} from '@/api/cover.js';
	import {
		detail,
		boss
	} from '@/api/user.js';
	import {
		lists
	} from '@/api/author/opus.js';
	export default {
		data() {
			return {
				is_statement: false,
				is_copyright: true,
				is_wechat: false,
				copyright: '1、该页面内容由创作者发布在本平台\n2、部分内容来源于网络，侵权及时联系\n3、与创作者私下交易，自行承担风险',
				subsection: ['金牌作者', '官方认证'],
				current: 1,
				userInfo: {},
				author_id: '',
				opus: [],
				state: 10,
				page: 1,
				is_reach: false,
				author: {},
				tabs: []
			};
		},
		onLoad(options) {
			this.author_id = options.author_id
			if (!this.author_id) {
				uni.navigateBack()
			}
		},
		onShow() {
			this.getBoss()
			this.getUser()
		},
		onShareTimeline() {
			let _this = this
			return {
				title: "推荐一个红包封面创作者@" + _this.author.real_name
			}
		},
		onShareAppMessage() {
			let _this = this
			return {
				title: "推荐一个红包封面创作者@" + _this.author.real_name
			}
		},
		onReachBottom() {
			let _this = this
			_this.is_reach = true
			_this.page = _this.page + 1
			_this.getOpus()
		},
		methods: {
			onCopyPassword() {
				let password = this.author_id
				if (this.userInfo) {
					password = this.userInfo.user_id + "T" + this.author_id
				}
				uni.setClipboardData({
					data: password
				})
			},
			onSubmitOrder(opus_id) {
				uni.navigateTo({
					url: '/pages/author/buy/index?opus_id=' + opus_id
				})
			},
			onCloseAll() {
				this.is_copyright = false
				this.is_statement = false
				this.is_wechat = false
			},
			getCategory() {
				category({}).then(res => {
					let tabs = [{
						name: '全部',
						category_id: ''
					}]
					let category = res.data.category
					for (let i in category) {
						let arr = {}
						arr.name = category[i].name
						arr.category_id = category[i].category_id
						tabs.push(arr)
					}
					this.tabs = tabs
				}).catch(err => {

				})
			},
			getOpus() {
				let _this = this
				lists({
					state: _this.state,
					page: _this.page,
					user_id: _this.author_id
				}).then(res => {
					if (_this.is_reach) {
						_this.opus = [...this.opus, ...res.data.opus.data]
					} else {
						_this.opus = res.data.opus.data
					}
					_this.is_reach = false
				}).catch(err => {

				})
			},
			getBoss() {
				boss({
					user_id: this.author_id
				}).then(res => {
					this.author = res.data.author
					this.getOpus()
				}).catch(err => {

				})
			},
			getUser() {
				detail({}).then(res => {
					this.userInfo = res.data.userInfo
				}).catch(err => {

				})
			},
		}
	}
</script>

<style lang="scss">
	.btn-group {
		width: 90%;
		margin: 0 auto;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		margin-top: 30rpx;

		.right {
			display: flex;
			flex-direction: row;

			.btn {
				margin-left: 15rpx;
			}
		}

		.left {
			display: flex;
			flex-direction: row;
		}

		.u-button {
			height: 70rpx !important;
			font-size: 28rpx !important;
		}
	}

	.cover {
		width: 92%;
		display: flex;
		flex-direction: row;
		justify-content: space-between;
		flex-wrap: wrap;
		margin: 0 auto;

		.image {
			width: 210rpx;
			border-radius: 15rpx;
			overflow: hidden;
			margin: 15rpx 0rpx;
		}
	}

	.tabs {
		background-color: #fff;
		padding: 30rpx;
		padding-top: 15rpx;
	}

	.header {
		width: 100%;
		background-image: url('https://img.alicdn.com/imgextra/i3/2064565174/O1CN01azmlui1o5k3Cj4sql_!!2064565174.jpg');
		background-size: contain;

		.remarks {
			width: 90%;
			margin: 0 auto;
			color: #909399;
		}

		.user {
			display: flex;
			flex-direction: row;
			align-items: center;
			justify-content: space-between;
			padding: 60rpx 30rpx;
			padding-bottom: 30rpx;
			padding-top: 20rpx;

			.right {
				width: 210rpx;
				padding: 0rpx 15rpx;
				background-color: #fff;
				border-radius: 30rpx 0rpx 0rpx 30rpx;
				overflow: hidden;
			}

			.left {
				display: flex;
				flex-direction: row;
				align-items: center;

				.nickName {
					.bottom {
						font-size: 20rpx;
						margin-top: 15rpx;
					}

					.top {
						display: flex;
						flex-direction: row;

						.name {
							font-weight: bolder;
							margin-right: 10rpx;
							font-size: 28rpx;
						}
					}
				}

				.avatar {
					width: 120rpx;
					height: 120rpx;
					border-radius: 50%;
					border: 5rpx solid #c8c9cc;
					margin-right: 15rpx;
				}
			}
		}
	}
</style>
